
use std::fmt::Display;

#[derive(Debug)]
pub enum List<T> where T: Clone + Display{
	Cons(T, Box<List<T>>),
	Nil,
}

impl<T> List<T> where T: Clone + Display {
	pub fn new() -> List<T> {
		List::Nil
	}

	pub fn prepend(self, elem: T) -> List<T> {
		List::Cons(elem, Box::new(self))
	}

	pub fn len(&self) -> usize {
		match *self {
			List::Cons(_, ref tail) => 1 + tail.len(),
			List::Nil => 0,
		}
	}

	pub fn is_empty(&self) -> bool {
		self.len() == 0
	}

	pub fn stringify(&self) -> String {
		match *self {
			List::Cons(ref head, ref tail) => {
				format!("{}, {}", head, tail.stringify())
			},
			List::Nil =>  format!("Nil"),
		}
	}
}


